<template>
  <div class="tinymce-editor">
  <editor
  v-model="myValue"
  apiKey="sg12zjr8q1x033q5c492c4afofgfk0xwwxv6ltm69nper2d7"
  initialValue="<p>Initial editor content</p>"
    :init="init"
  >
  </editor>
  </div>
</template>

<script>
// import '@npkg/tinymce-plugins/importword'
import tinymce from 'tinymce/tinymce'
import Editor from '@tinymce/tinymce-vue'
import 'tinymce/themes/silver/theme'
import 'tinymce/plugins/image'
import 'tinymce/plugins/media'
import 'tinymce/plugins/table'
import 'tinymce/plugins/lists'
import 'tinymce/plugins/contextmenu'
import 'tinymce/plugins/wordcount'
import 'tinymce/plugins/colorpicker'
import 'tinymce/plugins/textcolor'
import 'tinymce/plugins/importword'

export default{
  components:{
    editor: Editor
  },
  props: {
    //传入一个value，使组件支持v-model绑定
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    plugins: {//插件参数
      type: [String, Array],
      default: 'print lists image media table textcolor wordcount contextmenu importword'
    },
    toolbar: {
      type: [String, Array],
      default: 'print | undo redo |  formatselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists image media table | removeformat importword'
    }
  },
  data(){
    return {
      init: {
        language: 'zh_CN',
        height: 900,
        plugins: this.plugins,
        toolbar: this.toolbar,
        branding: false,
        menubar: false,
        images_upload_handler: (blobInfo, success, failure) => {//图片处理
          const img = 'data:image/jpeg;base64,' + blobInfo.base64()
          success(img)
        }
      },
      myValue: this.myValue
    }
  },
  mounted(){
    tinymce.init({});
  },
  methods: {
    clear(){
      this.myValue = ''
    }
  },
  watch: {
    value(newValue) {
      this.myValue = newValue
    },
    myValue(newValue) {
      this.$emit('input', newValue)
    }
  }
}
</script>

<style scoped>
</style>